extends Control



const TscnColumn = preload("res://tool/page/dataRegister/coinConsume/CoinConsumeColumn.tscn")

#onready var search_input = $searchBox/LineEdit

func _ready():
	state_update()
	pass 



func state_update():
	update_list(DataSource.get_data_list(DataSource.coin_consume))
	


func update_list(map_list):
	var box = $table/ScrollContainer/VBoxContainer
	
	for child in box.get_children():
		child.queue_free()
		
	for data in map_list:
		var ui_item = TscnColumn.instance()
		ui_item.set_data(data)
		box.add_child(ui_item)
		
		ui_item.connect("edit", self, "_on_edit")
		ui_item.connect("delete", self, "_on_delete")
	


func _on_addBtn_button_up():
	var ui = MainTool.getUILayer().add_ui("res://tool/page/dataRegister/coinConsume/CoinConsumeModal.tscn", 0, false)
	
	ui.connect("close", self, "state_update")

func _on_edit(map_data):
	var ui = MainTool.getUILayer().add_ui("res://tool/page/dataRegister/coinConsume/CoinConsumeModal.tscn", 0, false)
	
	ui.set_edit_data(map_data)
	ui.connect("close", self, "state_update")

func _on_delete(data):
	MainTool.confirm("你是否确认删除金币消耗数据", self, "_on_del_ok", null, data)



func _on_del_ok(data):
	DataSource.delete_data_by(DataSource.coin_consume, data["id"])
	state_update()
	
	MainTool.toast_info("删除成功!")
